package com.example.dynamicdatasourcetest.util;

import com.example.dynamicdatasourcetest.datasource.DataSourceConst;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
@Component
public class DynamicDataSourceUtil implements InitializingBean {
    private  Map<String,Boolean>  dataSourceTypeMap;


    public  Boolean checkDataSourceType(String dsType) {

        if (dataSourceTypeMap.get(dsType)!=null){
            return dataSourceTypeMap.get(dsType);
        }
        return false;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.dataSourceTypeMap = new HashMap<>();
        if (dataSourceTypeMap.isEmpty()){
            dataSourceTypeMap.put(DataSourceConst.DEFAULT_DATASOURCE,true);
            dataSourceTypeMap.put(DataSourceConst.DATASOURCE_TEST2,true);
        }
    }
}
